package besteAukera;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.util.Vector;

public class DBiegonkorra extends Sekuentzialak {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Color kolorea;
	private Vector<Hanka> hankaBektorea = new Vector<Hanka>();
	private Vector<Hanka> sarreraBektorea = new Vector<Hanka>();
	private Hanka s1, s2, i1, i2, s3;

	public DBiegonkorra(int x1, int y1, int hankaKop, int sarreraKopMax, Color kolorea) {
		super(x1, y1, hankaKop, sarreraKopMax, kolorea);
		// TODO Auto-generated constructor stub

		s1 = new Hanka(x - 20, y + 40, "positiboa", "s", 0, this, "h", "ez",true);

		s2 = new Hanka(x + 30, y - 20, "negatiboa", "s", 1, this, "b", "ez",true);
		s3 = new Hanka(x + 30, y + 100, "negatiboa", "s", 2, this, "b", "bai",true);
		i1 = new Hanka(x + 80, y + 28, "positiboa", "i", 3, this, "h", "ez",true);
		i2 = new Hanka(x + 80, y + 52, "negatiboa", "i", 4, this, "h", "ez",true);

		lotList[0] = s1;
		lotList[1] = s2;
		lotList[2] = s3;
		lotList[3] = i1;
		lotList[4] = i2;

	}

	public void marraztu(Graphics g) {

		if (getAukeratua() == true) {
			kolorea = Color.GRAY;
		} else {
			kolorea = Color.black;
		}
		g.setColor(kolorea);
		// goikoa
		g.drawLine(x, y, x + 60, y);
		// beikoa
		g.drawLine(x + 60, y, x + 60, y + 80);
		// ezkerretakoa
		g.drawLine(x + 60, y + 80, x, y + 80);
		// eskubitakoa
		g.drawLine(x, y + 80, x, y);

		g.drawLine(x - 10, y + 75, x, y + 75);
		g.drawLine(x - 10, y + 85, x - 10, y + 75);
		Font lehenetsia=g.getFont();
		Font f=new Font("name",Font.BOLD,9);
		g.setFont(f);
		g.drawString(">", x, y + 80);

		g.drawString("D", x + 2, y + 43);

		g.drawString("PR*.L", x + 15, y + 12);
		g.drawString("Q", x + 50, y + 33);
		g.drawString("Q.L", x + 40, y + 55);

		g.drawString("CL*.L", x + 15, y + 78);
		g.setColor(kolorea);
		g.setFont(lehenetsia);
		s1.marraztu(g);
		s2.marraztu(g);
		i1.marraztu(g);
		i2.marraztu(g);

		s3.marraztu(g);

	}

	public boolean barruanDago(int x, int y) {
		if ((x > this.x) && (x < (this.x + 60)) && (y > this.y)
				&& (y < (this.y + 80))) {
			return true;
		}
		return false;

	}

	@Override
	public void funtzioLogikoa(Integer... values) {

		// TODO Auto-generated method stub
		if ((s2.getSarrera().getBalioa() == 0)
				&& (s3.getSarrera().getBalioa() == 1)) {
			lotList[3].getIrteera().setBalioa(0);
			lotList[4].getIrteera().setBalioa(0);
		}
		if ((s2.getSarrera().getBalioa() == 1)
				&& (s3.getSarrera().getBalioa() == 0)) {
			lotList[3].getIrteera().setBalioa(1);
			lotList[4].getIrteera().setBalioa(1);
		}

		if ((s2.getSarrera().getBalioa() == 0)
				&& (s3.getSarrera().getBalioa() == 0)
				&& (s1.getSarrera().getBalioa() == 0)) {
			lotList[3].getIrteera().setBalioa(0);
			lotList[4].getIrteera().setBalioa(0);
		}
		if ((s2.getSarrera().getBalioa() == 0)
				&& (s3.getSarrera().getBalioa() == 0)
				&& (s1.getSarrera().getBalioa() == 1)) {
			lotList[3].getIrteera().setBalioa(1);
			lotList[4].getIrteera().setBalioa(1);
		}

	}

	@Override
	public Vector<Hanka> getHankak() {
		// TODO Auto-generated method stub
		hankaBektorea = new Vector<Hanka>();
		hankaBektorea.addElement(s1);
		hankaBektorea.addElement(s2);
		hankaBektorea.addElement(s3);

		hankaBektorea.addElement(i1);
		hankaBektorea.addElement(i2);

		return hankaBektorea;
	}

	@Override
	public Vector<Hanka> getSarreraHankak() {
		// TODO Auto-generated method stub
		sarreraBektorea = new Vector<Hanka>();
		sarreraBektorea.addElement(s1);
		sarreraBektorea.addElement(s2);
		sarreraBektorea.addElement(s3);

		return sarreraBektorea;
	}

}
